package com.yjh;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Random;


//这个类是生成批量的数据的类
public class AddData {
    public static void main(String[] args) {
//        条数
        int number = 10000;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://hadoop103:3306/db01", "root", "123456");
            String sql = "insert into t2 values (?,?)";

            for (int i = 0; i < number; i++) {
                PreparedStatement pstmt = conn.prepareStatement(sql);
                pstmt.setInt(1,i);
                Random random = new Random();
                Integer i1 = random.nextInt(100);
                pstmt.setString(2,i1.toString());
                pstmt.executeUpdate();
                pstmt.close();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
